package com.java.member.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.java.member.vo.MemberVO;


@Controller
public class MemberController {
	
	
	@RequestMapping(value={"/Main.do"})
	public String login(HttpSession session,MemberVO vo){
		try {      
			session.setAttribute("login_info", vo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "memberTest.mem";
	}
	
	@RequestMapping(value={"/memberLogin.do"}, method=RequestMethod.GET)
	public String showLogin(){
		System.out.println("=] Display Login Form");
		return "login_success.mem";
	}
	
	@RequestMapping(value={"/memberLogin.do"}, method = RequestMethod.POST)
	public ModelAndView memberLogin(HttpSession session,MemberVO vo){
		ModelAndView mv = new ModelAndView();
		if(vo.getMember_id() != null){
			session.setAttribute("login_info", vo);
		}
		mv.setViewName("login_success.mem");
		return mv;
	}
	
	@RequestMapping(value={"/index.do"}, method= RequestMethod.GET)
	public ModelAndView main1(HttpSession session, HttpServletRequest request, HttpServletResponse response){
		ModelAndView mv = new ModelAndView("login_success.mem");
		return mv;
				
	}
	
	@RequestMapping(value={"/loginOut.do"})
	public ModelAndView memberLoginOut(HttpSession session){
		ModelAndView mv = new ModelAndView();
		if(session!=null){
			session.invalidate();
			mv.setViewName("login_success.mem");
		}
		return mv;
	}
}
